export default {
    async : {
        waitings : {},
        lockStatus : {}
    },
    //
    //锁
    //lock: 锁的编号
    //action: 解锁后执行的方法
    //
    lock: function (lock, action) {
        this.async.waitings[lock] = this.async.waitings[lock] || [];
        this.async.waitings[lock].push(action);
        //如果该锁未被使用，则当前action阻塞该锁
        if (!this.async.lockStatus[lock] && action) {
            this.async.lockStatus[lock] = true;
            action();
        }
    },
    //
    //解锁
    //lock: 锁的编号
    //
    releaseLock: function (lock) {
        this.async.waitings[lock].shift();
        //如果等待队列有对象，则执行等待队列，否则解锁
        if (this.async.waitings[lock].length) {
            this.async.waitings[lock][0]();
        } else {
            this.async.lockStatus[lock] = false;
        }
    },
    //
    //锁的状态
    //
    lockStatus: [],
    //
    //等待事件完成
    //lock:锁编码，相同的编码将被整合成一个序列，触发时同时触发
    //
    wait: function (lock , action) {
        this.async.waitings[lock] = this.async.waitings[lock] || [];
        this.async.waitings[lock].push(action);
    },
 
}
